package model

import "ginblog/dao"

//User 用户结构体
type User struct {
	ID         int    `form:"id"`
	Username   string `form:"username"`
	Password   string `form:"password"`
	Status     int    `form:"status"` //0是启用 1是停用
	Createtime int64  `form:"createtime"`
}

//AddUser 添加用户
func AddUser(u *User) (err error) {
	err = dao.DB.Create(u).Error
	return
}

//GetUser 查询用户，通过用户名密码查询
func GetUser(u *User) (err error) {
	err = dao.DB.Where("username = ? AND password = ?", u.Username, u.Password).First(&User{}).Error
	return
}

//GetUserLogin 查询用户，通过用户名查询用户是否存在
func GetUserLogin(name string) (islogin bool, err error) {
	err = dao.DB.Where("username=?", name).Find(&User{}).Error
	//查不到返回false
	if err == nil {
		islogin = false
	} else { //查到返回true
		islogin = true
	}
	return
}
